from django.db import models

from DjangoUeditor.models import UEditorField

malf_status = (
    (0, "处理中"),
    (1, "未处理"),
    (2, "关闭"),
)

source_data = (
    (0, "zabbix"),
    (1, "nagios"),
    (2, "cacti"),
    (3, "smokeping"),
    (4, "监控脚本"),
    (5, "监控宝"),
    (6, "其它"),
)

grade_data = (
    (0, "高危"),
    (1, "严重"),
    (2, "中级"),
    (3, "一般"),
    (4, "无影响"),
)


class Incident(models.Model):
    """ 故障事件 """
    title = models.CharField(max_length=256, verbose_name='标题')
    ip = models.GenericIPAddressField(protocol="IPv4", blank=True, null=True, verbose_name='ip')
    url = models.TextField(blank=True, null=True, verbose_name='URL')
    projectuser = models.CharField(max_length=32, verbose_name='业务负责人', help_text='业务维护人员,输入中文名称')
    closeuser = models.CharField(max_length=32, blank=True, null=True, verbose_name='故障处理人员')
    # type = models.IntegerField(verbose_name="机房类型", choices=source_data, max_length=32, blank=True, null=True)
    source = models.IntegerField(choices=source_data, verbose_name='报障来源')
    starttime = models.DateTimeField(verbose_name='发生时间')
    scantime = models.DateTimeField(verbose_name='发现时间', blank=True, null=True, )
    stoptime = models.DateTimeField(blank=True, null=True, verbose_name='结束时间')

    mailcomment = UEditorField('报警内容', width=600, height=300, filePath="", upload_settings={"imageMaxSize": 1204000},
                               settings={}, command=None, blank=True)

    status = models.IntegerField(verbose_name="处理状态", choices=malf_status, default=1)
    classical = models.BooleanField(default=0, verbose_name='设为案例')
    grade = models.IntegerField(verbose_name='故障等级', blank=True, null=True, choices=grade_data)

    comment = UEditorField('处理过程', width=600, height=300, filePath="", upload_settings={"imageMaxSize": 1204000},
                           settings={}, command=None, blank=True, default="")
    project_principal = models.CharField(verbose_name='项目负责人', max_length=32, null=True, blank=True, default="",
                                         help_text="如需要邮件通知项目负责人,请填写项目负责人邮箱")
    incident_user = models.CharField(max_length=32, blank=True, null=True, verbose_name='故障创建人')
    createtime = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.title

    class Meta:
        managed = True
        db_table = 'incident'
        verbose_name = "故障管理"
        verbose_name_plural = verbose_name
